package com.bw.shopping.mvvm.view;


import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bw.mvvm.arouter.MyARouter;
import com.bw.mvvm.mvvm.view.BaseActivity;
import com.bw.shopping.BR;
import com.bw.shopping.R;
import com.bw.shopping.databinding.ActivitySeckillBinding;
import com.bw.shopping.mvvm.model.entity.SeckillAction;
import com.bw.shopping.mvvm.viewmodel.SeckillViewModel;
import com.bw.shopping.time.TimeService;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

@Route(path = MyARouter.SECKILL)
public class SeckillActivity extends BaseActivity<ActivitySeckillBinding, SeckillViewModel> {

    boolean serviceFlag = false;
    public TimeService timeService;

    @Override
    public int bindLayout() {
        return R.layout.activity_seckill;
    }

    @Override
    public int initVerable() {
        return BR.seckill;
    }

    ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            TimeService.TimeBinder binder = (TimeService.TimeBinder) iBinder;
            timeService = binder.getService();
        }
        @Override
        public void onServiceDisconnected(ComponentName componentName) {

        }
    };


    @Override
    protected void onResume() {
        super.onResume();
        if (serviceFlag){
            Intent intent = new Intent(this, TimeService.class);
            bindService(intent,connection,BIND_ABOVE_CLIENT);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (serviceFlag){
            unbindService(connection);
        }
    }
}
